using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SimpleEnemy : CharacterController
{
    public Trigger2D m_MoveTrigger2D;
    public Trigger2D m_ForwardTrigger2D;
    public Trigger2D m_FallTrigger2D;
    public Trigger2D m_AttackTrigger2D;

    public CharacterMovement m_CharacterMovement;

    private void Awake()
    {
        m_CharacterMovement.enabled = false;
        m_MoveTrigger2D.m_OnEnterTrigger.AddListener(() => {
            m_CharacterMovement.enabled = true;
        });

        m_MoveTrigger2D.m_OnExitTrigger.AddListener(() => {
            m_CharacterMovement.enabled = false;
        });

        m_ForwardTrigger2D.m_OnEnterTrigger.AddListener(() => {
            var localScale = transform.localScale;
            localScale.x *= -1;
            transform.localScale = localScale;
        });


        m_FallTrigger2D.m_OnExitTrigger.AddListener(() => {
            var localScale = transform.localScale;
            localScale.x *= -1;
            transform.localScale = localScale;
        });

        m_AttackTrigger2D.m_OnEnterTriggerWithCollider.AddListener((collider2D) => {
            AttackBackJump attackBackJump = gameObject.GetComponent<AttackBackJump>();
            attackBackJump?.Execute(collider2D.gameObject);
            PlayerHit playerHit = collider2D.GetComponent<PlayerHit>();
            playerHit?.ExecuteHit();
        });
    }
}
